//
//  BIDPersonalRepairStatusView.m
//  HJGJCommunity
//
//  Created by mal on 2017/6/7.
//  Copyright © 2017年 mal. All rights reserved.
//

#import "BIDPersonalRepairStatusView.h"
#import "BIDRepairStatusCell.h"

@interface BIDPersonalRepairStatusView()<UITableViewDelegate, UITableViewDataSource>
{
    NSMutableArray *_dataSourceArr;
    BOOL _bRegister;
    NSDictionary *_repairDic;
}

@end

@implementation BIDPersonalRepairStatusView

- (id)initWithFrame:(CGRect)frame andDic:(NSDictionary *)dic
{
    self = [super initWithFrame:frame];
    if(self)
    {
        _repairDic = [[NSDictionary alloc] initWithDictionary:dic];
        NSArray *arr = @[@{@"statusName":@"待处理", @"time":@"", @"status":@0, @"isShowRemarks":@0},
                         @{@"statusName":@"已派工", @"time":@"", @"status":@1, @"isShowRemarks":@1},
                         @{@"statusName":@"已完成", @"time":@"", @"status":@2, @"isShowRemarks":@0},
                         @{@"statusName":@"已评价", @"time":@"", @"status":@3, @"isShowRemarks":@1}];
        _dataSourceArr = [[NSMutableArray alloc] initWithArray:arr];
        self.bounces = NO;
        [self setBackgroundColor:RGBACOLOR(239.f, 239.f, 239.f, 1.f)];
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.allowsSelection = NO;
        self.delegate = self;
        self.dataSource = self;
    }
    return self;
}


#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSourceArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    static NSString *identifier = @"identifier";
    NSUInteger row = indexPath.row;
    if(!_bRegister)
    {
        _bRegister = YES;
        UINib *nib = [UINib nibWithNibName:@"BIDRepairStatusCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:identifier];
    }
    BIDRepairStatusCell *statusCell = [tableView dequeueReusableCellWithIdentifier:identifier];
    statusCell.indexPath = indexPath;
    NSDictionary *dic = _dataSourceArr[row];
    NSNumber *statusValue = _repairDic[@"status"];
    switch(row)
    {
        case 0:
        {
            if(ISNULL(_repairDic[@"waitSolveTime"])){}
            else statusCell.timeLabel.text = _repairDic[@"waitSolveTime"];
        }
            break;
        case 1:
        {
            if(ISNULL(_repairDic[@"setMenTime"])){}
            else statusCell.timeLabel.text = _repairDic[@"setMenTime"];
        }
            break;
        case 2:
        {
            if(ISNULL(_repairDic[@"finishTime"])){}
            else statusCell.timeLabel.text = _repairDic[@"finishTime"];
        }
            break;
        case 3:
        {
            if(ISNULL(_repairDic[@"confirmTime"])){}
            else statusCell.timeLabel.text = _repairDic[@"confirmTime"];
        }
            break;
    }
    if([statusValue intValue] < row)
    {
        statusCell.flagImgView.image = [UIImage imageNamed:@"smile_normal.png"];
    }
    else
    {
        statusCell.flagImgView.image = [UIImage imageNamed:@"smile_highlight.png"];
    }
    statusCell.statusLabel.text = dic[@"statusName"];
    NSNumber *isShowRemarksValue = dic[@"isShowRemarks"];
    if([isShowRemarksValue intValue]==0)
    {
        statusCell.remarksBtn.hidden = YES;
    }
    else
    {
        statusCell.remarksBtn.hidden = NO;
    }
    if(row==0)
    {
        statusCell.topLineLabel.hidden = YES;
    }
    else
    {
        statusCell.topLineLabel.hidden = NO;
    }
    if(row == 3)
    {
        statusCell.behindLineLabel.hidden = YES;
    }
    else
    {
        statusCell.behindLineLabel.hidden = NO;
    }
    cell = statusCell;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 78.f;
}

@end
